home *** CD-ROM | disk | FTP | other *** search
/ Gekikoh Dennoh Club 3 / Gekikoh Dennoh Club Vol. 3 (Japan).7z / Gekikoh Dennoh Club Vol. 3 (Japan) (Track 1).bin / docs / panda / play.c < prev    next >
C/C++ Source or Header  |  1998-02-19  |  7KB  |  387 lines

  1. /*
  2.     qv2 play
  3. */
  4.  
  5. #include    <stdio.h>
  6. #include    <stdlib.h>
  7. #include    <io.h>
  8. #include    <graph.h>
  9. #include    <doslib.h>
  10. #include    <iocslib.h>
  11.  
  12. char    Y_TBL[65536];
  13.  
  14.  
  15. unsigned short *gbuf;
  16.  
  17.  
  18. int    main(argc,argv)
  19. int    argc;
  20. char    *argv[];
  21. {
  22.     FILE    *fp;
  23.     int    fn,tfn;
  24.     short    *addr;
  25. //    int    sx=48,sy=84;        //補正しない
  26.     int    sx=48,sy=38;        //補正する
  27.     int    len;
  28.     int    ed;
  29.     int    ssp;
  30.     int    mode=0;
  31.     
  32.     screen(1,3,1,1);
  33.     if( argc!=1 ){
  34.         CRTMOD(270);
  35.     }
  36.     printf("計算中…\n");
  37.     mktbl();
  38.     printf("データ読み込み中…\n");
  39.     fp=fopen("panda.qv2","rb");
  40.     len=filelength(fileno(fp));
  41.     gbuf=MALLOC(len);
  42.     if( (int)gbuf<0 ){
  43.         printf("メモリ不足\n");
  44.         fclose(fp);
  45.         goto quick_exit;
  46.     }
  47.     fread(gbuf,2,len/2,fp);
  48.     fclose(fp);
  49.     cls();
  50.     
  51.     ssp=B_SUPER(0);
  52.     cls();
  53.     ed=len/38400;
  54.     while(1){
  55.         for( fn=1;fn<=ed;fn++ ){
  56.             printf("\x0d%03d ",fn);
  57. //            put(sx,sy,sx+159,sy+119,gbuf+19200*(fn-1),38400);    //160*120
  58.  
  59. /*
  60.             putQV2wf(sx,sy,gbuf+19200*(fn-1));    //160*120
  61. */
  62.  
  63.             switch( BITSNS(0x00) ){
  64.                 case 0x00:    //
  65.                     putQV2wn(sx,sy,gbuf+19200*(fn-1));    //160*120
  66.                     printf("no");
  67.                 break;
  68.                 case 0x04:    //1
  69.                     putQV2wf(sx,sy,gbuf+19200*(fn-1));    //160*120
  70.                     printf("fi");
  71.                 break;
  72.                 case 0x08:    //2
  73.                     putQV2wc(sx,sy,gbuf+19200*(fn-1));    //160*120
  74.                     printf("c0");
  75.                 break;
  76.                 case 0x10:    //3
  77.                     putQV2wcc(sx,sy,gbuf+19200*(fn-1));    //160*120
  78.                     printf("cc");
  79.                 break;
  80.                 case 0x20:    //4
  81.                     if( fn&1 ){
  82.                         putQV2wn(sx,sy,gbuf+19200*(fn-1));    //160*120
  83.                     }
  84.                     else{
  85.                         putQV2wf(sx,sy,gbuf+19200*(fn-1));    //160*120
  86.                     }
  87.                     printf("nf");
  88.                 break;
  89.             }
  90.  
  91.             if( BITSNS(0x00)==0x02 ){
  92.                 goto quick_exit;
  93.             }
  94.         }
  95.     }
  96.     B_SUPER(ssp);
  97.  
  98. quick_exit:;
  99.     KFLUSHIO(0xff);
  100.     
  101. }
  102.  
  103.  
  104.  
  105.  
  106. int    mktbl()
  107. {
  108.     int col;
  109.     int    r,g,b,gray;
  110.     
  111.     for( col=0;col<=0xffff;col++ ){
  112.         r=(col&0b0000011111000000)>>6;
  113.         g=(col&0b1111100000000000)>>11;
  114.         b=(col&0b0000000000111110)>>1;
  115. //        0.299 0.587 0.114
  116.         r*=1000;
  117.         g*=1000;
  118.         b*=1000;
  119.         gray=r*0.299+g*0.587+b*0.114;
  120.         gray/=1000;
  121.         Y_TBL[col]=(char)gray;
  122.     }
  123.  
  124. }
  125.  
  126.  
  127.  
  128.  
  129. //単純補間
  130. int    putQV2wn(px,py,addr)
  131. int    px,py;
  132. unsigned short    *addr;
  133. {
  134.     int    x,y;
  135.     unsigned short *s,*d;
  136.     
  137.     s=addr;
  138.     d=(unsigned short *)0xc00000+py*512+px;
  139.     for( y=0;y<120;y+=2 ){
  140.         //偶数ラインは2重描画
  141.         for( x=0;x<20;x++ ){
  142.             *d++=*s++;*d++=*s++;*d++=*s++;*d++=*s++;*d++=*s++;*d++=*s++;*d++=*s++;*d++=*s++;
  143.         }
  144.         d+=352;        //512-160
  145.         s-=160;
  146.         for( x=0;x<20;x++ ){
  147.             *d++=*s++;*d++=*s++;*d++=*s++;*d++=*s++;*d++=*s++;*d++=*s++;*d++=*s++;*d++=*s++;
  148.         }
  149.         d+=352;        //512-160
  150.  
  151.         for( x=0;x<20;x++ ){
  152.             *d++=*s++;*d++=*s++;*d++=*s++;*d++=*s++;*d++=*s++;*d++=*s++;*d++=*s++;*d++=*s++;
  153.         }
  154.         d+=352;        //512-160
  155.     }
  156. }
  157.  
  158.  
  159.  
  160.  
  161. //櫛形補間
  162. int    putQV2wf(px,py,addr)
  163. int    px,py;
  164. unsigned short    *addr;
  165. {
  166.     int    x,y;
  167.     unsigned short *s,*d;
  168.     
  169.     s=addr;
  170.     d=(unsigned short *)0xc00000+py*512+px;
  171.     for( y=0;y<120;y+=2 ){
  172.  
  173. /*
  174.     uuuu
  175.     udud
  176.     dddd
  177. */
  178.         //u
  179.         for( x=0;x<20;x++ ){
  180.             *(d+512)=*s;    *d++=*s++;    *d++=*s++;
  181.             *(d+512)=*s;    *d++=*s++;    *d++=*s++;
  182.             *(d+512)=*s;    *d++=*s++;    *d++=*s++;
  183.             *(d+512)=*s;    *d++=*s++;    *d++=*s++;
  184.         }
  185. //        d+=352;        //(512-160)+512
  186.         d+=864;        //(512-160)+512
  187.  
  188.         //d
  189.         for( x=0;x<20;x++ ){
  190.             *d++=*s++;    *(d-512)=*s;    *d++=*s++;
  191.             *d++=*s++;    *(d-512)=*s;    *d++=*s++;
  192.             *d++=*s++;    *(d-512)=*s;    *d++=*s++;
  193.             *d++=*s++;    *(d-512)=*s;    *d++=*s++;
  194.         }
  195.         d+=352;        //512-160
  196.  
  197.     }
  198. }
  199.  
  200.  
  201.  
  202. //色差計算
  203. int    putQV2wc(px,py,addr)
  204. int    px,py;
  205. unsigned short    *addr;
  206. {
  207.     int    x,y;
  208.     unsigned short *su,*sd,*du,*dm,*dd;
  209.     unsigned short    uc,mc,dc,    ur,ug,ub,    dr,dg,db,    mr,mg,mb;
  210.  
  211.     su=addr;
  212.     sd=addr+160;
  213.     du=(unsigned short *)0xc00000+py*512+px;
  214.     dm=(unsigned short *)0xc00000+py*512+px+512;
  215.     dd=(unsigned short *)0xc00000+py*512+px+1024;
  216.  
  217.     for( y=0;y<120;y+=2 ){
  218.  
  219.         //u意味なしか
  220.         for( x=0;x<40;x++ ){    *du++=*su++;*du++=*su++;*du++=*su++;*du++=*su++;    }
  221.  
  222.         //d
  223.         for( x=0;x<40;x++ ){    *dd++=*sd++;*dd++=*sd++;*dd++=*sd++;*dd++=*sd++;    }
  224.  
  225.         su-=160;
  226.         sd-=160;
  227.  
  228.         for( x=0;x<160;x++ ){
  229.             //レジスタがたりんぞい
  230.             uc=*su++;
  231.             dc=*sd++;
  232.             ur=(uc&0b0000011111000000)>>6;
  233.             ug=(uc&0b1111100000000000)>>11;
  234.             ub=(uc&0b0000000000111110)>>1;
  235.             dr=(dc&0b0000011111000000)>>6;
  236.             dg=(dc&0b1111100000000000)>>11;
  237.             db=(dc&0b0000000000111110)>>1;
  238.             mr=((ur+dr)>>1)<<6;
  239.             mg=((ug+dg)>>1)<<11;
  240.             mb=((ub+db)>>1)<<1;
  241.             mc=mr;
  242.             mc|=mg;
  243.             mc|=mb;
  244.             *dm++=mc;
  245.         }
  246.  
  247.         du+=1376;        //(512-160)+1024
  248.         dm+=1376;
  249.         dd+=1376;
  250.         su+=160;
  251.         sd+=160;
  252.  
  253.     }
  254.  
  255.  
  256. }
  257.  
  258.  
  259.  
  260.  
  261. //色差検査後計算orコピー
  262. int    putQV2wcc(px,py,addr)
  263. int    px,py;
  264. unsigned short    *addr;
  265. {
  266.     int    x,y;
  267.     unsigned short *su,*sd,*du,*dm,*dd;
  268.     unsigned short    uc,mc,dc,    ur,ug,ub,    dr,dg,db,    mr,mg,mb;
  269.     
  270.     su=addr;
  271.     sd=addr+160;
  272.     du=(unsigned short *)0xc00000+py*512+px;
  273.     dm=(unsigned short *)0xc00000+py*512+px+512;
  274.     dd=(unsigned short *)0xc00000+py*512+px+1024;
  275.  
  276.     for( y=0;y<120;y+=2 ){
  277.  
  278.         //u意味なしか
  279.         for( x=0;x<40;x++ ){    *du++=*su++;*du++=*su++;*du++=*su++;*du++=*su++;    }
  280.  
  281.         //d
  282.         for( x=0;x<40;x++ ){    *dd++=*sd++;*dd++=*sd++;*dd++=*sd++;*dd++=*sd++;    }
  283.  
  284.         su-=160;
  285.         sd-=160;
  286.  
  287.         for( x=0;x<160;x++ ){
  288.             //レジスタがたりんぞい
  289.             uc=*su++;
  290.             dc=*sd++;
  291.  
  292. //            printf("%d,",(max((int)Y_TBL[uc],(int)Y_TBL[dc])-min((int)Y_TBL[uc],(int)Y_TBL[dc])));
  293.  
  294.             if( (max((int)Y_TBL[uc],(int)Y_TBL[dc])-min((int)Y_TBL[uc],(int)Y_TBL[dc]))>=12 ){
  295.                 //37.5%以上の輝度変化があった場合
  296.                 ur=(uc&0b0000011111000000)>>6;
  297.                 ug=(uc&0b1111100000000000)>>11;
  298.                 ub=(uc&0b0000000000111110)>>1;
  299.                 dr=(dc&0b0000011111000000)>>6;
  300.                 dg=(dc&0b1111100000000000)>>11;
  301.                 db=(dc&0b0000000000111110)>>1;
  302.                 mr=((ur+dr)>>1)<<6;
  303.                 mg=((ug+dg)>>1)<<11;
  304.                 mb=((ub+db)>>1)<<1;
  305.                 mc=mr;
  306.                 mc|=mg;
  307.                 mc|=mb;
  308.                 *dm++=mc;
  309.             }
  310.             else{
  311.                 //変化が少なければ上の色をそのまま
  312.                 *dm++=uc;
  313.             }
  314.  
  315.         }
  316.  
  317.         du+=1376;        //(512-160)+1024
  318.         dm+=1376;
  319.         dd+=1376;
  320.         su+=160;
  321.         sd+=160;
  322.  
  323.     }
  324.  
  325.  
  326. }
  327.  
  328.  
  329.  
  330.  
  331. //色差計算for 68060
  332. int    putQV2wc060(px,py,addr)
  333. int    px,py;
  334. unsigned short    *addr;
  335. {
  336.     int    x,y;
  337.     unsigned short *su,*sd,*du,*dm,*dd;
  338.     unsigned short    uc,mc,dc,    ur,ug,ub,    dr,dg,db,    mr,mg,mb;
  339.  
  340.     su=addr;
  341.     sd=addr+160;
  342.     du=(unsigned short *)0xc00000+py*512+px;
  343.     dm=(unsigned short *)0xc00000+py*512+px+512;
  344.     dd=(unsigned short *)0xc00000+py*512+px+1024;
  345.  
  346.     for( y=0;y<120;y+=2 ){
  347.  
  348.         for( x=0;x<160;x++ ){
  349.  
  350.             uc=*su++;
  351.             dc=*sd++;
  352.  
  353.             *du++=uc;
  354.             *dd++=dc;
  355.  
  356.             uc&=0b0000011111000000;
  357.             uc>>=6;
  358.             ur=uc;                //@@以下、
  359.             ug=(uc&0b1111100000000000)>>11;
  360.             ub=(uc&0b0000000000111110)>>1;
  361.             dr=(dc&0b0000011111000000)>>6;
  362.             dg=(dc&0b1111100000000000)>>11;
  363.             db=(dc&0b0000000000111110)>>1;
  364.             mr=((ur+dr)>>1)<<6;
  365.             mg=((ug+dg)>>1)<<11;
  366.             mb=((ub+db)>>1)<<1;
  367.             mc=mr;
  368.             mc|=mg;
  369.             mc|=mb;
  370.             *dm++=mc;
  371.         }
  372.  
  373.         du+=1376;        //(512-160)+1024
  374.         dm+=1376;
  375.         dd+=1376;
  376.         su+=160;
  377.         sd+=160;
  378.  
  379.     }
  380.  
  381.  
  382. }
  383.  
  384.  
  385.  
  386.  
  387.